//
//  ArrayDataSource.m
//  27--ArrayDataSource
//
//  Created by 冀永金 on 16/8/19.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ArrayDataSource.h"

@interface ArrayDataSource ()
@property (nonatomic, copy) NSString *reuse;
@property (nonatomic, retain) NSArray *arrayDataSource;
// 必须写成属性
@property (nonatomic, copy) ConfigCell configCell;
@end
@implementation ArrayDataSource
- (instancetype)initWithTableViewCellReuse:(NSString *)reuse arrayDataSource:(NSArray *)array configCell:(ConfigCell)configCell{
    self = [super init];
    if (self) {
        _reuse = reuse;
        _arrayDataSource = array;
        _configCell = configCell;
        
    }
    return self;
}
+ (instancetype)arrayWithTableViewCellReuse:(NSString *)reuse arrayDataSource:(NSArray *)array configCell:(ConfigCell)configCell{
    return [[self alloc]initWithTableViewCellReuse:reuse arrayDataSource:array configCell:configCell];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrayDataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:_reuse forIndexPath:indexPath];
    id model = _arrayDataSource[indexPath.row];
    self.configCell(cell,model);
    return cell;
}


@end
